﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Product_Product : BLL.AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        BLL.PageManage.doPaging("T_Product", webPage, rep_list);
    }

    //删除选中选项
    protected void btnDelAll_Click(object sender, EventArgs e)
    {
        //foreach (RepeaterItem item in rep_list.Items)
        //{
        //    if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
        //    {
        //        Literal lit = item.FindControl("litItemID") as Literal;
        //        CheckBox ckb = item.FindControl("CheckBox") as CheckBox;
        //        if (ckb.Checked)
        //        {
        //            string sql = "delete from qProduct where ID = @ID";
        //            SqlHelper.ExecuteScalar(sql, SqlHelper.SetParameter("@ID", lit.Text));
        //        }
        //    }
        //}
        //Response.Write("<script>alert('删除成功')</script>");
        //BindData();
    }

    // 删除事件
    protected void btnDel_Click(object sender, EventArgs e)
    {
        //LinkButton btn = sender as LinkButton;
        //string AdvID = btn.CommandArgument.ToString();
        //string sql = "delete from qProduct where ID = @ID";
        //SqlHelper.ExecuteScalar(sql, SqlHelper.SetParameter("@ID", AdvID));
        //Response.Write("<script>alert('删除成功')</script>");
        //BindData();

        LinkButton btn = sender as LinkButton;
        string AdvID = btn.CommandArgument.ToString();
        var product = ctx.T_Product.Single(p => p.ID.ToString().Equals(AdvID));
        ctx.T_Product.DeleteOnSubmit(product);
        ctx.SubmitChanges();
        Response.Write("<script>alert('删除成功');</script>");
        BindData();
    }
    protected void webPage_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }
}